home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Lists / ListLoop.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  2.9 KB  |  83 lines  |  [TEXT/CWIE]

  1. // ListLoop.h
  2.  
  3. #ifndef ListLoop_h
  4. #define ListLoop_h
  5.  
  6. #ifndef ListLink_h
  7. #include "ListLink.h"
  8. #endif
  9. #ifndef SequenceLoop_h
  10. #include "SequenceLoop.h"
  11. #endif
  12. #ifndef ListOf_h
  13. #include "ListOf.h"
  14. #endif
  15.  
  16. template < class Target >
  17. class ListLoop: private SequenceLoop<List,ListNode>
  18.   {
  19.     typedef ListLink<Target> LinkType;
  20.     typedef ListOf<Target> HeadType;
  21.     typedef ListLoop<Target> LoopType;
  22.     typedef SequenceLoop<List,ListNode> Inherited;
  23.     
  24.     private:
  25.         static const ListLink<Target> *DownCast( const ListNode *n )
  26.           {
  27.             return static_cast< const ListLink<Target>* >( n );
  28.           }
  29.  
  30.         static const ListOf<Target>& DownCast( const List& n )
  31.           {
  32.             return static_cast< const ListOf<Target>& >( n );
  33.           }
  34.         
  35.     public:
  36.         ListLoop( const HeadType& h )                                        : Inherited( h )                    {}
  37.         ListLoop( const HeadType& h, AtStart )                            : Inherited( h, atStart )        {}
  38.         ListLoop( const HeadType& h, AtEnd )                            : Inherited( h, atEnd )            {}
  39.         ListLoop( const HeadType& h, Nowhere )                            : Inherited( h, nowhere )        {}
  40.         ListLoop( const HeadType& h, const LinkType& p )            : Inherited( h, p )                {}
  41.         ListLoop( const HeadType& h, Before, const LinkType& p )    : Inherited( h, before, p )    {}
  42.         ListLoop( const HeadType& h, After, const LinkType& p )    : Inherited( h, after, p )        {}
  43.         ListLoop( const HeadType& h, BeforeStart )                    : Inherited( h, beforeStart )    {}
  44.         ListLoop( const HeadType& h, AfterEnd )                        : Inherited( h, afterEnd )        {}
  45.  
  46.         const HeadType& Owner() const                        { return DownCast( Inherited::Owner() ); }
  47.         
  48.         Inherited::Finished;
  49.         Inherited::Unfinished;
  50.  
  51.         Inherited::MoveToFinish;
  52.         Inherited::MoveToFirst;
  53.         Inherited::MoveToLast;
  54.         Inherited::MoveBeforeFirst;
  55.         Inherited::MoveAfterLast;
  56.         
  57.         void MoveTo( const LinkType& p )                    { Inherited::MoveTo( p ); }
  58.         void MoveBefore( const LinkType& p )            { Inherited::MoveBefore( p ); }
  59.         void MoveAfter( const LinkType& p )                { Inherited::MoveAfter( p ); }
  60.                     
  61.         bool operator==( const LoopType& r ) const    { return Inherited::operator==( r ); }
  62.         bool operator!=( const LoopType& r ) const    { return Inherited::operator!=( r ); }
  63.  
  64.         bool operator==( const LinkType& r ) const    { return Inherited::operator==( r ); }
  65.         bool operator!=( const LinkType& r ) const    { return Inherited::operator!=( r ); }
  66.             
  67.         Inherited::Null;
  68.         const LinkType *Position() const        { return DownCast( Inherited::Position() ); }
  69.         
  70.         const LinkType *Next() const            { return DownCast( Inherited::Next() ); }
  71.         const LinkType *Previous() const        { return DownCast( Inherited::Previous() ); }
  72.         
  73.         Target& operator*() const        { return **DownCast( Inherited::operator->() ); }
  74.         Target *operator->() const        { return &**DownCast( Inherited::operator->() ); }
  75.         
  76.         void operator++()                            { Inherited::operator++(); }
  77.         void operator++(int)                        { Inherited::operator++(0); }
  78.         void operator--()                            { Inherited::operator--(); }
  79.         void operator--(int)                        { Inherited::operator--(0); }
  80.   };
  81.  
  82. #endif
  83.